package com.jxm.hutools;

import cn.hutool.core.util.ReUtil;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * @Author: jxm
 * @Description:
 * @Date: 2023-12-18 16:44
 * @Version: 1.0
 */
public class PatternTest {

    @Test
    public void test1(){
        String content = "ZZZaaabbbccc中文1234";
        String resultExtractMulti = ReUtil.extractMulti("(\\w)aa(\\w)", content, "$1-$2");
        System.out.println(resultExtractMulti);
        Assert.assertEquals("Z-a", resultExtractMulti);
    }

    //查找所有匹配文本
    @Test
    public void test2(){
        //查找所有匹配文本
        String content = "ZZZaaabbbccc中文1234";
        List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<String>());
// 结果：["ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34"]
        resultFindAll.forEach(item->{
            System.out.println(item);
        });

        //找到匹配的第一个数字
        Integer resultGetFirstNumber = ReUtil.getFirstNumber(content);
        System.out.println(resultGetFirstNumber);
    }

}
